package fy.hr.dao;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.json.JSONObject;

import com.soa.eis.adapter.framework.message.IMsgObject;
import com.soa.eis.adapter.framework.message.impl.GroupRecord;
import com.soa.eis.adapter.framework.requester.IServiceRequester;
import com.soa.eis.adapter.framework.requester.impl.BaseServiceRequester;

import fy.hr.bean.PersonInfoBean;

public class FindPersonInfoDao2 {
	
	private String[] codes;


	// private List<GroupRecord> record2 ;
	IMsgObject respMo = null;
	//private long userID;
//	private AwayFormBean afBean = new AwayFormBean();
	
/*	public static void main(String[] args) throws Exception {
		JSONObject record2=new FindPersonInfoDao().findPersonInfo();
		System.out.println(record2.toString());
 		
	}
	
*/
	private boolean needTime = false;
	private boolean newAway = false;
	
	//V3xOrgMember member = MyOrgManager.getInstance().getMemberByID(userID);
	private static Log log = LogFactory.getLog(FindPersonInfoDao2.class);
	public JSONObject findPersonInfo() throws Exception {
		try{
	/*	System.out.println("??????????????");
		String mil=String.valueOf(System.currentTimeMillis());
	//	String sHttpPost = "http://10.112.0.206:7080/httpservice";
		String sHttpPost = "http://10.112.5.133:7080/httpservice";
		IMsgObject reqMo = new MsgObject(IMsgObject.MOType.initSR);
		String SourceSysID = "06004";              //请求方(发布方) 系统号    OA  
		String ServiceID = "06003000000001"; //响应方(发布方) 服务号    HR
		//获取系统时间
		Date date = new Date();
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
		String format = simpleDateFormat.format(date);
		reqMo.setSourceSysID(SourceSysID); //设置报文 请求方系统号      
		reqMo.setServiceID(ServiceID);     //设置报文 提供方服务号
		reqMo.setSerialNO(format.substring(0, 8)+SourceSysID+System.currentTimeMillis());//设置报文流水号,第三段表示今天发送的第几的一次报文
		reqMo.setServiceDateTime(format);  //设置报文 日期时间
		System.out.println("++++++++++++++");
		log.info("**************************************************");
		V3xOrgMember member = MyOrgManager.getInstance().getMemberByID(userID);
		if( member!=null){
			//String userCode=member.getCode();
			System.out.println(">>>>>>>>>>"+ member);
		}	
	//	String userCode=member.getCode();
		//String userCode="000521";
		
	//	String userCode=codes;
		for (int i = 0, length = this.codes.length; i < length; i++) {
			reqMo.setReqValue("string",  this.codes[i]);
		}
		System.out.println("???????????????+"+codes);
		reqMo.setReqValue("string", userCode);*/
			
		//com.seeyon.ctp.form.service.FormDataController
		//PersonInfoBean PB=new PersonInfoBean();
	   //reqMo.setReqValue("string", );
			
	//	IMsgObject respMo = null;	
	//	log.info("reqMo:" + reqMo.toString());

		//直接访问WSDL调用方法
	//	MYWSServiceRequester mt = new MYWSServiceRequester(sHttpPost);
	//	System.out.println("??????????????");
/*		respMo = mt.execute(reqMo);
		
		log.info(">>>>>>>>>>>>>>>"+respMo);

		System.out.println(">>>>>>>>>>>>>>>"+respMo);
		*/
		
		JSONObject jo = new JSONObject();

		// 获取服务调用者实例
		for (int i = 0, length = this.codes.length; i < length; i++) {
			// System.out.println("~~~~~~~~~~~~~~~~"+codes.length+codes[i]);
			// System.out.println("~~~~~~~~~~~~~~~~"+codes.length+codes[i]);
			IServiceRequester Requester = BaseServiceRequester.getInstance();
		/*	// 定义请求报文对象
			IMsgObject reqMo = new MsgObject(IMsgObject.MOType.initSR);
			String SourceSysID = "06004"; // 请求方(发布方) 系统号
			String ServiceID = "06003000000008";// 响应方(发布方) 服务号
			// 获取系统时间
			Date date = new Date();
			SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
			String format = simpleDateFormat.format(date);
			// 对请求报文对象进行设置
			reqMo.setSourceSysID(SourceSysID); // 设置报文 请求方系统号
			reqMo.setServiceID(ServiceID); // 设置报文 提供方服务号
			
		//	reqMo.setSerialNO(format.substring(0, 8) + SourceSysID + "00000");// 设置报文流水号,第三段表示今天发送的第几的一次报文
			reqMo.setSerialNO(format.substring(0, 8) + SourceSysID + String.format("%06d", ++RequestNoTimerTask.requestNo));// 设置报文流水号,第三段表示今天发送的第几的一次报文
	

	
			reqMo.setServiceDateTime(format);
			reqMo.setReqValue("string",codes[i]);
		// reqMo.setReqValue("string", "084655");
			//reqMo.setReqValue("string", codes[i]);
			// 打印请求报文对象
			LogUtil.getInstance().info("reqMo:" + reqMo);*/
			//String lsid=format.substring(0, 8) + SourceSysID + String.format("%06d", ++RequestNoTimerTask.requestNo)
			IMsgObject reqMo= MqReqXml.add("06004", "06003000000008", codes[i]);
	//	System.out.println("reqMo:"+reqMo);
			respMo = Requester.execute(reqMo);
			log.info("respMo:"+respMo);
			System.out.println("" + respMo);
		List<GroupRecord> record2 = respMo.getResGroupRecord("return") ;
		for (GroupRecord groupRecord : record2) {
			String pk_tbm_psndoc=groupRecord.getFieldValue("pk_tbm_psndoc");
			System.out.println("??????????????"+groupRecord.getFieldValue("basgroupdef23")+groupRecord.getFieldValue("id")+groupRecord.getFieldValue("mobile"));
			if(groupRecord.getFieldValue("psncode")==null){
			
			
			}else{
	
			PersonInfoBean pib = new PersonInfoBean();
			pib.setCode(groupRecord.getFieldValue("psncode"));
			pib.setName(groupRecord.getFieldValue("psnname"));
			pib.setDep(groupRecord.getFieldValue("deptname"));
			pib.setPost(groupRecord.getFieldValue("jobname"));
			pib.setExistPk_tbm_psndoc((pk_tbm_psndoc == null
					|| "".equals(pk_tbm_psndoc) ? false : true));
			pib.setPk_corp(groupRecord.getFieldValue("pk_corp"));
			
			if (this.needTime) {
				pib.setDate(groupRecord.getFieldValue("basgroupdef4"));
			}
			if(this.newAway){
				pib.setBasgroupdef23(groupRecord.getFieldValue("basgroupdef23"));
				pib.setId(groupRecord.getFieldValue("id"));
				if(i==0){
				pib.setMobile(groupRecord.getFieldValue("mobile"));}
			}

			jo.put(pib.getID(), pib.getJSONObject());
		}	}}
// 		list 转jsonboject
 		return jo;}
		catch(Exception e){
			log.error("******************************AAAAAAAAAAAAAAAAAAAAAAAAAAAAAa", e);
		}
		return null;
 		
 		
	}
	
	public void setCodes(String[] codesArray) {
	this.codes = codesArray;
}
	public void setNeedTime(boolean needTime) {
		this.needTime = needTime;
	}
	public void setNewAway(boolean newAway) {
		this.newAway = newAway;
	}
}
/*package fy.hr.dao;



import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

import com.soa.eis.adapter.framework.exception.EisException;
import com.soa.eis.adapter.framework.message.IMsgObject;
import com.soa.eis.adapter.framework.message.impl.GroupRecord;
import com.soa.eis.adapter.framework.message.impl.MsgObject;
import com.soa.eis.adapter.framework.requester.IServiceRequester;
import com.soa.eis.adapter.framework.requester.impl.BaseServiceRequester;
import com.soa.eis.adapter.framework.utils.log.LogUtil;

public class FindPersonInfoDao {
	*//**
	 * 使用BaseServiceRequester进行服务调用
	 * @throws Exception 
	 *//*
	public void requester() throws Exception{
		// 获取服务调用者实例
		IServiceRequester Requester = BaseServiceRequester.getInstance();
		// 定义请求报文对象
		IMsgObject reqMo = new MsgObject(IMsgObject.MOType.initSR);
		String SourceSysID = "06001";       //请求方(发布方) 系统号
		String ServiceID = "06001100000002";//响应方(发布方) 服务号
		//获取系统时间
		Date date = new Date();
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
		String format = simpleDateFormat.format(date);
		//对请求报文对象进行设置
		reqMo.setSourceSysID(SourceSysID); //设置报文 请求方系统号      
		reqMo.setServiceID(ServiceID);     //设置报文 提供方服务号
		
		reqMo.setSerialNO(format.substring(0, 8)+SourceSysID+"000001");//设置报文流水号,第三段表示今天发送的第几的一次报文


//		reqMo.setControlValue("Username", "GUESTERM");
//		reqMo.setControlValue("Password", "GUESTERM");
//		


		
		//人员发布
	reqMo.setReqValue("ControlType", "5");
		
		List<GroupRecord> grs1 = new ArrayList<GroupRecord>();
		GroupRecord gr1 = new GroupRecord();
		gr1.setName("ROW");
		gr1.setFieldValue("SERIALNO", "2017030906001000237");
		gr1.setFieldValue("DISTRI_DATA_ID", "22");
		gr1.setFieldValue("BIRTHDAY", "1979-08-24");
		gr1.setFieldValue("SEX", "男");
		gr1.setFieldValue("COUNTRY", "HI200000000000002002");
		gr1.setFieldValue("NATIVEPLACE", "HRPMPLYA000000001274");
		gr1.setFieldValue("MOBILEPHONE", "13859013287");		
		gr1.setFieldValue("EDUCATION", "0001K71000000000054B");
		gr1.setFieldValue("MAJOR", "汽车制造与维修");
		gr1.setFieldValue("UNIVERSITIES", "福建职业技术学院");
		gr1.setFieldValue("IN_TIME", "2002-05-01");
		gr1.setFieldValue("ORGANIZATION", "1008");
		gr1.setFieldValue("DUTY_STATUS", "0");
		gr1.setFieldValue("EPLOYEE_TYPE", "0001K7100000000001PF");
		gr1.setFieldValue("TELEPHONE", "05947795151");
		gr1.setFieldValue("EMAIL", "xiaowenjin998@163.com");
		gr1.setFieldValue("WORKING_YEARS", "");
		gr1.setFieldValue("POST_NAME", "1008N3100000000CY2L7");
		gr1.setFieldValue("VERSION", "");
		gr1.setFieldValue("STATUS", "");
		gr1.setFieldValue("CREATE_DATE", "2016-12-22 09:23:14");
		gr1.setFieldValue("CREATE_MAN", "");
		gr1.setFieldValue("UPDATE_DATE", "");
		gr1.setFieldValue("UPDATE_MAN", "");
		grs1.add(gr1);
//				
		reqMo.setReqGroupRecord(grs1);
		
		
		

		
	
		//打印请求报文对象
		LogUtil.getInstance().info(reqMo);
		


		
		IMsgObject respMo = null;
		try{
			long start = System.currentTimeMillis();
			//传入请求报文对象，返回响应报文对象。
			respMo = Requester.execute(reqMo);
			long end = System.currentTimeMillis();
			LogUtil.getInstance().info("\n");
			LogUtil.getInstance().info("本次请求共耗时: "+ (end-start) + "毫秒");
			LogUtil.getInstance().info("\n");
			LogUtil.getInstance().info("///////////////////////////////XML格式化打印//////////////////////////////////");
			LogUtil.getInstance().info(respMo);
			
			
//

			
			
		} catch(Exception e) {
			e.printStackTrace();
		}
	}
	

	public static void main(String args[]) throws EisException, IOException
	{		
		try {
			new FindPersonInfoDao().requester();
		} catch (Exception e) {
			LogUtil.getInstance().error(EisException.getTrace(e)); 
		}
	}

}*/







